#ifndef FUNCTION_H
#define FUNCTION_H

#include <QObject>
#include <QHash>
#include "misc.h"
#include "DAL/dal.h"
#include "cenum.h"
#include <dbmanager.h>


extern Sqlite * bSqlite;

typedef QString (QObject:: *P_FUNC)(MsgDatagram &);

typedef QHash<QString, P_FUNC> HashFunc;

class Function : public QObject
{
    Q_OBJECT
public:
    explicit Function(QObject *parent = nullptr);
    QString flag="";
    QString callFuncByKey(QString key, MsgDatagram &msg);
    QString handle(MsgDatagram &msg);
    
    QString function00(MsgDatagram &);  //用户注册
    QString function01(MsgDatagram &);  //用户登陆
    QString function02(MsgDatagram &);  //病人排队
    QString function03(MsgDatagram &);  //病人预约/取消预约
    QString function04(MsgDatagram &);  //基本信息
    QString function05(MsgDatagram &);  //修改基本信息
    QString function06(MsgDatagram &);  //修改密码
    QString function07(MsgDatagram &);  //手机端用户是否预约

    QString function21(MsgDatagram &);  //设备端登陆
    QString function22(MsgDatagram &);  //设备端病人信息
    QString function23(MsgDatagram &);  //设备端数据
    QString function24(MsgDatagram &);  //设备端删除病人信息

    QString function99(MsgDatagram &);  //获取设备种类

signals:
    void sendDevice(QString);

private:
    bool checkUserInfo(QString phoneNum,QString password);
    QString cutOutOperationType(QString choose);
    int findMaxreservaNum();    //查找最大排队号
    int findOperationQueueCount(QString );
    int findReservaNum(QString phoneNum);  //根据手机号查找排队号码
    bool findPatientInformation(MsgDatagram& msg,QString sql);




private:
    HashFunc hashFunc;

};

#endif // FUNCTION_H
